/***************************************************************************
 *   Copyright (C) 2007 by Ivan Vasić                    *
 *   ivasic@gmail.com                     *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef BVALUENODE_H
#define BVALUENODE_H

#include "bnode.h"
#include <QVariant>

class QByteArray;

/**
 * @class BValueNode
 *
 * Terminalni čvor koji predstavlja podatak tipa INT ili STRING.
 * Realno može da bude string, 32 bitni integer ili 64 bitni integer.
 *
 * @author Ivan Vasić <ivasic@gmail.com>
*/
class BValueNode : public BNode
{

	public:

		/**
		 * @enum ValueType
		 * Tip vrednosti čvora.
		 */
		enum ValueType
		{
			STRING,
			INT,
			BIGINT
	};

		///Default konstruktor. Inicijalizuje BNode konstruktor.
		BValueNode(quint32 offset);

		///Konstruktor. Postavlja offset, tip čvora i vrednost čvora.
		BValueNode(quint32 offset, ValueType t, QVariant val);
		~BValueNode();

		///Vraća tip vrednosti čvora.
		ValueType type() const { return m_type; }

		///Vraća vrednost čvora.
		QVariant value() const { return m_value; }

		///Vraća string reprezentaciju vrednosti čvora bez obzira na tip.
		QString toString() const { return m_value.toString(); }

		///Vraća broj grana u ovom čvoru tj. uvek 0 jer je ovo terminalni čvor.
		int childCount() const { return 0; }

		///Setuje vrednost čvora.
		void setValue(const QVariant& val) { m_value = val; }		

		///Setuje tip čvora
		void setType(const ValueType& val) { m_type = val; }

	private:
		///Variant vrednosti čvora.
		QVariant m_value;

		///Tip vrednosti čvora.
		ValueType m_type;
};

#endif
